package cn.zzxy.day01;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 用DBUtil连接数据库并对数据库exam中的表dept进行查询
 */
public class Demo5 {
    public static void main(String[] args) throws Exception{
        Connection conn = DBUtils.getConn();
        Statement st = conn.createStatement();
        String sql = "select * from dept";
        ResultSet rs = st.executeQuery(sql);
        while(rs.next()){
            //通过字段对应的位置查询
            String no = rs.getString("deptno");
            String name = rs.getString(2);
            String loc = rs.getString(3);
            System.out.println(no+":"+name+":"+loc);
        }
        conn.close();
    }
}
